package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HmzCollectionSource;
import com.ruoyi.system.service.IHmzCollectionSourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 藏品来源Controller
 * 
 * @author ruoyi
 * @date 2023-11-25
 */
@RestController
@RequestMapping("/system/source")
public class HmzCollectionSourceController extends BaseController
{
    @Autowired
    private IHmzCollectionSourceService hmzCollectionSourceService;

    /**
     * 查询藏品来源列表
     */
    @PreAuthorize("@ss.hasPermi('system:source:list')")
    @GetMapping("/list")
    public TableDataInfo list(HmzCollectionSource hmzCollectionSource)
    {
        startPage();
        List<HmzCollectionSource> list = hmzCollectionSourceService.selectHmzCollectionSourceList(hmzCollectionSource);
        return getDataTable(list);
    }

    /**
     * 导出藏品来源列表
     */
    @PreAuthorize("@ss.hasPermi('system:source:export')")
    @Log(title = "藏品来源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HmzCollectionSource hmzCollectionSource)
    {
        List<HmzCollectionSource> list = hmzCollectionSourceService.selectHmzCollectionSourceList(hmzCollectionSource);
        ExcelUtil<HmzCollectionSource> util = new ExcelUtil<HmzCollectionSource>(HmzCollectionSource.class);
        util.exportExcel(response, list, "藏品来源数据");
    }

    /**
     * 获取藏品来源详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:source:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hmzCollectionSourceService.selectHmzCollectionSourceById(id));
    }

    /**
     * 新增藏品来源
     */
    @PreAuthorize("@ss.hasPermi('system:source:add')")
    @Log(title = "藏品来源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HmzCollectionSource hmzCollectionSource)
    {
        return toAjax(hmzCollectionSourceService.insertHmzCollectionSource(hmzCollectionSource));
    }

    /**
     * 修改藏品来源
     */
    @PreAuthorize("@ss.hasPermi('system:source:edit')")
    @Log(title = "藏品来源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HmzCollectionSource hmzCollectionSource)
    {
        return toAjax(hmzCollectionSourceService.updateHmzCollectionSource(hmzCollectionSource));
    }

    /**
     * 删除藏品来源
     */
    @PreAuthorize("@ss.hasPermi('system:source:remove')")
    @Log(title = "藏品来源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hmzCollectionSourceService.deleteHmzCollectionSourceByIds(ids));
    }
}
